﻿Imports System
Imports System.Web.Services
Imports VMWorkshop.Domain

Partial Public Class Ajax
    Inherits System.Web.UI.Page
    Private _vm As AjaxViewModel = Nothing

    Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
        Me._vm = New AjaxViewModel(New ProductRepository())
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Me.grdProducts.DataSource = Me._vm.Products
        Me.grdProducts.DataBind()
    End Sub

    <WebMethod()> _
    Public Shared Function GetProductById(ByVal productId As Integer) As ProductEditView
        Dim vm As New AjaxViewModel(New ProductRepository())
        Return vm.GetProductById(productId)
    End Function

    <WebMethod()> _
    Public Shared Sub PersistChanges(ByVal editView As ProductEditView)
        Dim vm As New AjaxViewModel(New ProductRepository())
        vm.PersistChanges(editView)
    End Sub
End Class